<template>
  <div id="main">
    <el-form
      ref="ruleFormRef"
      style="max-width: 300px"
      :model="ruleForm"
      status-icon
      :rules="rules"
      label-width="auto"
      class="demo-ruleForm"
    >
      <el-form-item label="用户名" prop="user">
        <el-input v-model="ruleForm.user" type="input" autocomplete="off" />
      </el-form-item>
      <el-form-item label="密码" prop="pass">
        <el-input
          v-model.trim="ruleForm.pass"
          type="password"
          show-password="true"
          autocomplete="on"
        />
      </el-form-item>
      <el-form-item >
        <el-button type="primary" @click="submitForm(ruleFormRef)" style="margin-left: 50px;">
          登录
        </el-button>
        <el-button @click="resetForm()" style="margin-right: 0px; margin-left: 100px;">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import type { FormInstance, FormRules } from "element-plus";

const ruleFormRef = ref<FormInstance>();

const ruleForm = reactive({
  user: "",
  pass: "",
});
 
const submitForm=async (ruleFormRef)=>{
  
}

const resetForm =()=>{

}

const CheckPass = (rule: any, value: any, callback: any) => {
  if (value === "") {
    callback(new Error("请输入密码"));
  } else {
    callback();
  }
};

const CheckUser = (rule: any, value: any, callback: any) => {
  if (value === "") {
    callback(new Error("请输入用户名"));
  } else {
    callback();
  }
};

const rules = reactive<FormRules<typeof ruleForm>>({
  pass: [{ validator: CheckPass, trigger: "blur" }],
  user: [{ validator: CheckUser, trigger: "blur" }],
});
</script>

<style scoped>
#main {
  background-color: rgb(255, 253, 119);
  width: 400px;
  padding: 50px;
  padding-left: 130px;
  border-radius: 25px;
  margin: 200px auto;
}
</style>
